using System;
using System.IO;
using FireStarter.CodeGeneration;
using FireStarterModeller.BO;
using NUnit.Framework;

namespace FireStarter.Test.CodeGeneration
{
    public class TestBOTestProjectGenerator : TestProjectGeneratorBase
    {
        protected override IProjectGenerator CreateProjectGenerator()
        {
            return new BOTestProjectGenerator();
        }

        protected override IProjectGenerator CreateProjectReadyToGenerate()
        {
            BOTestProjectGenerator projectGenerator = new BOTestProjectGenerator();
            CreateSolutionGenerator(projectGenerator);
            projectGenerator.ProjectPath = GetRootedPath(Path.Combine(TEST_PROJECTS_FOLDER, GetRandomString()));
            projectGenerator.ProjectName = "TestProject.Test.BO";
            projectGenerator.SolutionGenerator.ClassDefsString = TestUtilsCodeGen.GetRandomString();
            projectGenerator.ModelSolution.BOProjectName = GetRandomString();
            projectGenerator.ModelSolution.BOTestProjectName = GetRandomString();
            
            return projectGenerator;
        }

        private void AssertProjectGeneratedCorrectly(IProjectGenerator testBOProjectGenerator, ProjectFileManager boProjectFileManager)
        {
            string libFolderName = testBOProjectGenerator.SolutionGenerator.HabaneroReferencePath;
            libFolderName = Utilities.GetRelativePath(libFolderName, testBOProjectGenerator.ProjectPath);
            string projectFileName = testBOProjectGenerator.ProjectFileName;
            Assert.IsTrue(Directory.Exists(testBOProjectGenerator.ProjectPath));
            Assert.IsTrue(File.Exists(projectFileName));
            ProjectFileManager projectFileManager = new ProjectFileManager(projectFileName, CodeTemplateEnum.CSharpVisualStudio2005);
            Assert.AreEqual(OutputType.Library, projectFileManager.OutputType);
            string projectFileContents = File.ReadAllText(projectFileName);
            StringAssert.Contains(@"<Compile Include=""Properties\AssemblyInfo.cs"" />", projectFileContents);
            AssertHasProjectReference(projectFileContents, testBOProjectGenerator, boProjectFileManager);
            AssertHasReference(projectFileContents, string.Format(@"{0}\Habanero.Base.dll", libFolderName));
            AssertHasReference(projectFileContents, string.Format(@"{0}\Habanero.BO.dll", libFolderName));
            AssertHasReference(projectFileContents, string.Format(@"{0}\Habanero.DB.dll", libFolderName));
            AssertHasReference(projectFileContents, string.Format(@"{0}\nunit.framework.dll", libFolderName));
        }

        [Test]
        public void TestCreateBoProjectGenerator()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IProjectGenerator BoProjectGenerator = CreateProjectGenerator();
            //---------------Test Result -----------------------
            Assert.IsNotNull(BoProjectGenerator);
            Assert.IsInstanceOf(typeof(BOTestProjectGenerator), BoProjectGenerator);
        }

        [Test]
        public void TestGenerate_Fails_ModelClassesNotSet()
        {
            //---------------Set up test pack-------------------
            IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
            projectGenerator.SolutionGenerator.ModelClasses = null;
            //---------------Assert Precondition----------------
            Assert.IsNull(projectGenerator.SolutionGenerator.ModelClasses);
            //---------------Execute Test ----------------------
            try
            {
                projectGenerator.Generate();
                //---------------Test Result -----------------------
                Assert.Fail("Expected to throw an PropertyMissingException");
            }
            catch (PropertyMissingException ex)
            {
                Assert.AreEqual("ModelClasses", ex.PropertyName);
            }
        }

        [Test]
        public void TestGenerate_Creates_ProjectFile_IfDoesNotExist()
        {
            //---------------Set up test pack-------------------
            IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();

            ProjectFileManager boProjectFileManager = CreateRandomProjectFile(projectGenerator.ModelSolution.BOProjectName);
            //---------------Assert Precondition----------------
            Assert.IsFalse(File.Exists(projectGenerator.ProjectFileName));
            //---------------Execute Test ----------------------
            projectGenerator.Generate();
            //---------------Test Result -----------------------
            AssertProjectGeneratedCorrectly(projectGenerator, boProjectFileManager);
        }

        [Test]
        public void TestGenerate_Creates_TestBase()
        {
            //---------------Set up test pack-------------------
            IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            projectGenerator.Generate();
            //---------------Test Result -----------------------
            string path = projectGenerator.ProjectPath + Path.DirectorySeparatorChar + "TestBase.cs";
            Assert.IsTrue(File.Exists(path));
        }

        [Test]
        public void TestGenerate_Creates_TestUtilsShared()
        {
            //---------------Set up test pack-------------------
            IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            projectGenerator.Generate();
            //---------------Test Result -----------------------
            string path = projectGenerator.ProjectPath + Path.DirectorySeparatorChar + BOTestProjectGenerator.TEST_UTILS_FOLDER
                          + Path.DirectorySeparatorChar + "TestUtilsShared.cs";
            Assert.IsTrue(File.Exists(path));
        }


        [Ignore("REASON")] //TODO Mark 04 Oct 2010: Ignored Test - REASON
        [Test]
        public void TestGenerate_Creates_TestUtils_OneClass()
        {
            //---------------Set up test pack-------------------
            IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
            string className = TestUtilsCodeGen.GetRandomString();
            DMSolution solution = CreateDMSolution(projectGenerator, className);
            projectGenerator.SolutionGenerator.ModelClasses = solution.DefaultAssembly.ModelClasses;
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, projectGenerator.SolutionGenerator.ModelClasses.Count);
            Assert.IsFalse(String.IsNullOrEmpty(solution.BaseTestProjectName));
            //---------------Execute Test ----------------------
            projectGenerator.Generate();
            //---------------Test Result -----------------------
            string folder = projectGenerator.ProjectPath + Path.DirectorySeparatorChar + BOTestProjectGenerator.TEST_UTILS_FOLDER
                            + Path.DirectorySeparatorChar;
            Assert.IsTrue(File.Exists(folder + String.Format("TestUtilsCodeGen{0}.cs", className)));
            Assert.IsTrue(File.Exists(folder + String.Format("TestUtilsCodeGen{0}.Def.cs", className)));
        }

        [Test]
        public void TestGenerate_Creates_TestBO_OneClass()
        {
            //---------------Set up test pack-------------------
            IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
            string className = TestUtilsCodeGen.GetRandomString();
            DMSolution solution = CreateDMSolution(projectGenerator, className);
           
            projectGenerator.SolutionGenerator.ModelClasses = solution.DefaultAssembly.ModelClasses;
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, projectGenerator.SolutionGenerator.ModelClasses.Count);
            Assert.IsFalse(String.IsNullOrEmpty(solution.BaseTestProjectName));
            //---------------Execute Test ----------------------
            projectGenerator.Generate();
            //---------------Test Result -----------------------
            string folder = projectGenerator.ProjectPath + Path.DirectorySeparatorChar;
            Assert.IsTrue(File.Exists(folder + String.Format("Test{0}.cs", className)));
            Assert.IsTrue(File.Exists(folder + String.Format("Test{0}.Def.cs", className)));
        }


        [Test]
        public void TestGenerate_ShouldNotCreate_TestUtils_OneClass_WhenGenerateCodeFalse()
        {
            //---------------Set up test pack-------------------
            IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
            string className = TestUtilsCodeGen.GetRandomString();
            DMSolution solution = CreateDMSolution(projectGenerator, className);
            projectGenerator.SolutionGenerator.ModelClasses = solution.DefaultAssembly.ModelClasses;
            DMClass dmClass = (DMClass) projectGenerator.SolutionGenerator.ModelClasses[0];
            dmClass.GenerateCode = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.GenerateCode);
            //---------------Execute Test ----------------------
            projectGenerator.Generate();
            //---------------Test Result -----------------------
            string folder = projectGenerator.ProjectPath + Path.DirectorySeparatorChar + BOTestProjectGenerator.TEST_UTILS_FOLDER
                            + Path.DirectorySeparatorChar;
            Assert.IsFalse(File.Exists(folder + String.Format("TestUtilsCodeGen{0}.cs", className)));
            Assert.IsFalse(File.Exists(folder + String.Format("TestUtilsCodeGen{0}.Def.cs", className)));
            Assert.IsFalse(dmClass.NeedsRegeneration);
        }


        [Ignore("REASON")] //TODO Mark 04 Oct 2010: Ignored Test - REASON
        [Test]
        public void TestGenerate_ShouldNotCreate_TestUtils_OneClass_WhenGenerateCodeTrue()
        {
            //---------------Set up test pack-------------------
            IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
            string className = TestUtilsCodeGen.GetRandomString();
            DMSolution solution = CreateDMSolution(projectGenerator, className);
            projectGenerator.SolutionGenerator.ModelClasses = solution.DefaultAssembly.ModelClasses;
            DMClass dmClass = (DMClass) projectGenerator.SolutionGenerator.ModelClasses[0];
            dmClass.GenerateCode = true;
            //---------------Assert Precondition----------------
            Assert.IsTrue(dmClass.GenerateCode);
            Assert.IsFalse(String.IsNullOrEmpty(solution.BaseTestProjectName));
            //---------------Execute Test ----------------------
            projectGenerator.Generate();
            //---------------Test Result -----------------------
            string folder = projectGenerator.ProjectPath + Path.DirectorySeparatorChar + BOTestProjectGenerator.TEST_UTILS_FOLDER
                            + Path.DirectorySeparatorChar;
            Assert.IsTrue(File.Exists(folder + String.Format("TestUtilsCodeGen{0}.cs", className)));
            Assert.IsTrue(File.Exists(folder + String.Format("TestUtilsCodeGen{0}.Def.cs", className)));
            Assert.IsFalse(dmClass.NeedsRegeneration);
        }

        [Test]
        public void TestGenerate_ShouldNotCreate_TestBO_OneClass_WhenGenerateCodeFalse()
        {
            //---------------Set up test pack-------------------
            IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
            string className = TestUtilsCodeGen.GetRandomString();
            DMSolution solution = CreateDMSolution(projectGenerator, className);
            projectGenerator.SolutionGenerator.ModelClasses = solution.DefaultAssembly.ModelClasses;
            DMClass dmClass = (DMClass)projectGenerator.SolutionGenerator.ModelClasses[0];
            dmClass.GenerateCode = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.GenerateCode);
            //---------------Execute Test ----------------------
            projectGenerator.Generate();
            //---------------Test Result -----------------------
            string folder = projectGenerator.ProjectPath + Path.DirectorySeparatorChar;
            Assert.IsFalse(File.Exists(folder + String.Format("Test{0}.cs", className)));
            Assert.IsFalse(File.Exists(folder + String.Format("Test{0}.Def.cs", className)));
            Assert.IsFalse(dmClass.NeedsRegeneration);
        }

        [Test]
        public void TestGenerate_ShouldNotCreate_TestBO_OneClass_WhenGenerateCodeTrue()
        {
            //---------------Set up test pack-------------------
            IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
            string className = TestUtilsCodeGen.GetRandomString();
            DMSolution solution = CreateDMSolution(projectGenerator, className);
            projectGenerator.SolutionGenerator.ModelClasses = solution.DefaultAssembly.ModelClasses;
            DMClass dmClass = (DMClass)projectGenerator.SolutionGenerator.ModelClasses[0];
            dmClass.GenerateCode = true;
            //---------------Assert Precondition----------------
            Assert.IsTrue(dmClass.GenerateCode);
            //---------------Execute Test ----------------------
            projectGenerator.Generate();
            //---------------Test Result -----------------------
            string folder = projectGenerator.ProjectPath + Path.DirectorySeparatorChar;
            Assert.IsTrue(File.Exists(folder + String.Format("Test{0}.cs", className)));
            Assert.IsTrue(File.Exists(folder + String.Format("Test{0}.Def.cs", className)));
            Assert.IsFalse(dmClass.NeedsRegeneration);
        }


        [Ignore("REASON")] //TODO Mark 04 Oct 2010: Ignored Test - REASON
        [Test]
        public void TestGenerate_ShouldCreate_TestUtilsDef_OneClass_WhenNeedsRegenerationFalseButFileDoesNotExist()
        {
            //---------------Set up test pack-------------------
            IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
            string className = TestUtilsCodeGen.GetRandomString();
            DMSolution solution = CreateDMSolution(projectGenerator, className);
            projectGenerator.SolutionGenerator.ModelClasses = solution.DefaultAssembly.ModelClasses;
            DMClass dmClass = (DMClass)projectGenerator.SolutionGenerator.ModelClasses[0];
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            Assert.IsFalse(String.IsNullOrEmpty(solution.BaseTestProjectName));
            //---------------Execute Test ----------------------
            projectGenerator.Generate();
            //---------------Test Result -----------------------
            string folder = projectGenerator.ProjectPath + Path.DirectorySeparatorChar + BOTestProjectGenerator.TEST_UTILS_FOLDER
                            + Path.DirectorySeparatorChar;
            Assert.IsTrue(File.Exists(folder + String.Format("TestUtilsCodeGen{0}.cs", className)));
            Assert.IsTrue(File.Exists(folder + String.Format("TestUtilsCodeGen{0}.Def.cs", className)));
            Assert.IsFalse(dmClass.NeedsRegeneration);
        }

        [Ignore("REASON")] //TODO Mark 04 Oct 2010: Ignored Test - REASON
        [Test]
        public void TestGenerate_ShouldNotCreate_TestUtils_OneClass_WhenNeedsRegenerationTrue()
        {
            //---------------Set up test pack-------------------
            IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
            string className = TestUtilsCodeGen.GetRandomString();
            DMSolution solution = CreateDMSolution(projectGenerator, className);
            projectGenerator.SolutionGenerator.ModelClasses = solution.DefaultAssembly.ModelClasses;
            DMClass dmClass = (DMClass)projectGenerator.SolutionGenerator.ModelClasses[0];
            dmClass.NeedsRegeneration = true;
            //---------------Assert Precondition----------------
            Assert.IsTrue(dmClass.NeedsRegeneration);
            Assert.IsFalse(String.IsNullOrEmpty(solution.BaseTestProjectName));
            //---------------Execute Test ----------------------
            projectGenerator.Generate();
            //---------------Test Result -----------------------
            string folder = projectGenerator.ProjectPath + Path.DirectorySeparatorChar + BOTestProjectGenerator.TEST_UTILS_FOLDER
                            + Path.DirectorySeparatorChar;
            Assert.IsTrue(File.Exists(folder + String.Format("TestUtilsCodeGen{0}.cs", className)));
            Assert.IsTrue(File.Exists(folder + String.Format("TestUtilsCodeGen{0}.Def.cs", className)));
            Assert.IsFalse(dmClass.NeedsRegeneration);
        }

        [Test]
        public void TestGenerate_ShouldNotCreate_TestBO_OneClass_WhenNeedsRegenerationTrue()
        {
            //---------------Set up test pack-------------------
            IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
            string className = TestUtilsCodeGen.GetRandomString();
            DMSolution solution = CreateDMSolution(projectGenerator, className);
            projectGenerator.SolutionGenerator.ModelClasses = solution.DefaultAssembly.ModelClasses;
            DMClass dmClass = (DMClass)projectGenerator.SolutionGenerator.ModelClasses[0];
            dmClass.NeedsRegeneration = true;
            //---------------Assert Precondition----------------
            Assert.IsTrue(dmClass.NeedsRegeneration);
            Assert.IsFalse(String.IsNullOrEmpty(solution.BaseTestProjectName));
            //---------------Execute Test ----------------------
            projectGenerator.Generate();
            //---------------Test Result -----------------------
            string folder = projectGenerator.ProjectPath + Path.DirectorySeparatorChar;
            Assert.IsTrue(File.Exists(folder + String.Format("Test{0}.cs", className)));
            Assert.IsTrue(File.Exists(folder + String.Format("Test{0}.Def.cs", className)));
            Assert.IsFalse(dmClass.NeedsRegeneration);
        }

        [Test]
        public void TestGenerate_ShouldCreateDefFileDoesNotExist_WhenGenerateCodeTrue()
        {
            //---------------Set up test pack-------------------
            IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
            string className = TestUtilsCodeGen.GetRandomString();
            DMSolution solution = CreateDMSolution(projectGenerator, className);
            projectGenerator.SolutionGenerator.ModelClasses = solution.DefaultAssembly.ModelClasses;
            DMClass dmClass = (DMClass)projectGenerator.SolutionGenerator.ModelClasses[0];
            dmClass.GenerateCode = false;
            dmClass.NeedsRegeneration = false;
            projectGenerator.Generate();
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.GenerateCode);
            Assert.IsFalse(dmClass.NeedsRegeneration);
            string folder = projectGenerator.ProjectPath + Path.DirectorySeparatorChar;
            Assert.IsFalse(File.Exists(folder + String.Format("Test{0}.cs", className)));
            Assert.IsFalse(File.Exists(folder + String.Format("Test{0}.Def.cs", className)));
            Assert.IsFalse(String.IsNullOrEmpty(solution.BaseTestProjectName));
            //---------------Execute Test ----------------------
            dmClass.GenerateCode = true;
            projectGenerator.Generate();
            //---------------Test Result -----------------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            folder = projectGenerator.ProjectPath + Path.DirectorySeparatorChar;
            Assert.IsTrue(File.Exists(folder + String.Format("Test{0}.cs", className)));
            Assert.IsTrue(File.Exists(folder + String.Format("Test{0}.Def.cs", className)));
        }

        private static DMSolution CreateDMSolution(IProjectGenerator projectGenerator, string className)
        {
            DMSolution solution = (DMSolution)projectGenerator.SolutionGenerator.ModelSolution;
            solution.DefaultAssembly = new DMAssembly();
            solution.BOProjectName = TestUtilsCodeGen.GetRandomString();
            solution.BaseTestProjectName = TestUtilsCodeGen.GetRandomString();
            DMClass dmClass = TestUtilsCodeGen.CreateModelClassOnProject(solution.DefaultAssembly, className);
            DMProperty dmProperty = TestUtilsCodeGen.CreatePKPropertyOnClass(dmClass, TestUtilsCodeGen.GetRandomString());
            TestUtilsCodeGen.SetPropertyType(dmProperty, "System", "String");
            return solution;
        }
        //[Test]
        //public void Test_DefFileAddedToProject_WhenDoesNotExist_GenerateCodeTrue_AndNeedsRegenerationSetToFalse()
        //{
        //    //---------------Set up test pack-------------------
        //    BoProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
        //    DMClass dmClass = (DMClass)projectGenerator.SolutionGenerator.ModelClasses[0];
        //    dmClass.NeedsRegeneration = false;
        //    dmClass.GenerateCode = false;
        //    projectGenerator.Generate();
        //    //---------------Assert Precondition----------------
        //    ProjectFileManager projectFileManager = new ProjectFileManager(projectGenerator.ProjectFileName, OutputType.Library, CodeTemplateEnum.CSharpVisualStudio2005);
        //    string fileName = Path.Combine(projectGenerator.ProjectPath, GetFileName());
        //    string stubFileName = Path.Combine(projectGenerator.ProjectPath, _className + ".cs");
        //    Assert.IsFalse(projectFileManager.HasCodeFile(fileName, stubFileName), "File Should be added to the project.");
        //    Assert.IsFalse(projectFileManager.HasCodeFile(stubFileName), "File Should be added to the project.");
        //    //---------------Execute Test ----------------------
        //    dmClass.GenerateCode = true;
        //    projectGenerator.Generate();
        //    //---------------Test Result -----------------------
        //    projectFileManager = new ProjectFileManager(projectGenerator.ProjectFileName, OutputType.Library, CodeTemplateEnum.CSharpVisualStudio2005);
        //    fileName = Path.Combine(projectGenerator.ProjectPath, GetFileName());
        //    stubFileName = Path.Combine(projectGenerator.ProjectPath, _className + ".cs");
        //    Assert.IsTrue(projectFileManager.HasCodeFile(stubFileName), "File Should be added to the project.");
        //    Assert.IsTrue(projectFileManager.HasCodeFile(fileName, stubFileName), "File Should be added to the project.");
        //}
    }
}


// OLD TESTS FOR OLD BO TEST IMPLEMENTATION, KEPT IN CASE WE DECIDE TO LOOK AT THE OLD STRUCTURE AGAIN (BRETT'S)

//using System;
//using System.Collections.Generic;
//using System.IO;
//using NUnit.Framework;
//using FireStarter.CodeGeneration;

//namespace FireStarter.Test.CodeGeneration
//{
//    [TestFixture]
//    public class TestBoTestProjectGenerator : TestProjectGeneratorBase
//    {
//        //        private static BoTestProjectGenerator CreateBoTestProjectReadyToGenerate()
//        //        {
//        //            BoTestProjectGenerator boTestProjectGenerator = new BoTestProjectGenerator("TestProject.Test.BO");
//        //            boTestProjectGenerator.BoProjectFileName = GetRootedPath(GetRandomProjectFileName());
//        //            boTestProjectGenerator.ProjectPath = GetRootedPath(Path.Combine(TEST_PROJECTS_FOLDER, GetRandomString()));
//        //            boTestProjectGenerator.ProjectName = "TestProject.Test.BO";
//        //            boTestProjectGenerator.HabaneroReferencePath = GetRootedPath(Path.Combine(TEST_PROJECTS_FOLDER, GetRandomString()));
//        //            boTestProjectGenerator.ModelElements = new List<IModelClass>();
//        //            return boTestProjectGenerator;
//        //        }
//        //
//        //        protected override IProjectGenerator CreateProjectGenerator()
//        //        {
//        //            return new BoTestProjectGenerator("TestProject.Test.BO");
//        //        }
//        //
//        //        protected override IProjectGenerator CreateProjectReadyToGenerate()
//        //        {
//        //            return CreateBoTestProjectReadyToGenerate();
//        //        }
//        //
//        //        private static void AssertProjectGeneratedCorrectly(BoTestProjectGenerator boTestProjectGenerator, ProjectFileManager boProjectFileManager)
//        //        {
//        //            string libFolderName = boTestProjectGenerator.HabaneroReferencePath;
//        //            libFolderName = Utilities.GetRelativePath(libFolderName, boTestProjectGenerator.ProjectPath);
//        //            string projectFileName = boTestProjectGenerator.ProjectFileName;
//        //            Assert.IsTrue(Directory.Exists(boTestProjectGenerator.ProjectPath));
//        //            Assert.IsTrue(File.Exists(projectFileName));
//        //            ProjectFileManager projectFileManager = new ProjectFileManager(projectFileName);
//        //            Assert.AreEqual(OutputType.Library, projectFileManager.OutputType);
//        //            string projectFileContents = File.ReadAllText(projectFileName);
//        //            StringAssert.Contains(@"<Compile Include=""Properties\AssemblyInfo.cs"" />", projectFileContents);
//        //            AssertHasProjectReference(projectFileContents, boTestProjectGenerator, boProjectFileManager);
//        //            AssertHasReference(projectFileContents, string.Format(@"{0}\Habanero.Base.dll", libFolderName));
//        //            AssertHasReference(projectFileContents, string.Format(@"{0}\Habanero.BO.dll", libFolderName));
//        //            AssertHasReference(projectFileContents, string.Format(@"{0}\Habanero.DB.dll", libFolderName));
//        //            AssertHasReference(projectFileContents, string.Format(@"{0}\Habanero.Util.dll", libFolderName));
//        //            AssertHasReference(projectFileContents, string.Format(@"{0}\nunit.framework.dll", libFolderName));
//        //        }
//        //
//        //        [Test]
//        //        public void TestCreateBoTestProjectGenerator()
//        //        {
//        //            //---------------Set up test pack-------------------
//        //
//        //            //---------------Assert Precondition----------------
//        //
//        //            //---------------Execute Test ----------------------
//        //            IProjectGenerator BoTestProjectGenerator = CreateProjectGenerator();
//        //
//        //            //---------------Test Result -----------------------
//        //            Assert.IsNotNull(BoTestProjectGenerator);
//        //            Assert.IsInstanceOf(typeof(BoTestProjectGenerator), BoTestProjectGenerator);
//        //        }
//        //
//        //        [Test]
//        //        public void TestBoProjectReference()
//        //        {
//        //            //---------------Set up test pack-------------------
//        //            string boProjectName = GetRandomString();
//        //            BoTestProjectGenerator boTestProjectGenerator = new BoTestProjectGenerator();
//        //            //---------------Assert Precondition----------------
//        //            Assert.IsNull(boTestProjectGenerator.BoProjectFileName);
//        //            //---------------Execute Test ----------------------
//        //            boTestProjectGenerator.BoProjectFileName = boProjectName;
//        //            //---------------Test Result -----------------------
//        //            Assert.AreEqual(boProjectName, boTestProjectGenerator.BoProjectFileName);
//        //        }
//        //
//        //        [Test]
//        //        public void TestGenerate_Fails_BoProjectReferenceNotSet()
//        //        {
//        //            //---------------Set up test pack-------------------
//        //            BoTestProjectGenerator boTestProjectGenerator = CreateBoTestProjectReadyToGenerate();
//        //            boTestProjectGenerator.BoProjectFileName = null;
//        //            //---------------Assert Precondition----------------
//        //            Assert.IsNull(boTestProjectGenerator.BoProjectFileName);
//        //            //---------------Execute Test ----------------------
//        //            Exception exception = null;
//        //            try
//        //            {
//        //                boTestProjectGenerator.Generate();
//        //            }
//        //            catch (Exception ex)
//        //            {
//        //                exception = ex;
//        //            }
//        //            //---------------Test Result -----------------------
//        //            Assert.IsNotNull(exception, "Exception Expected");
//        //            Assert.IsInstanceOf(typeof(ReferenceMissingException), exception);
//        //            ReferenceMissingException referenceMissingException = (ReferenceMissingException)exception;
//        //            Assert.AreEqual("BO Project", referenceMissingException.ReferenceName);
//        //        }
//        //
//        //        [Test]
//        //        public void TestModelClasses()
//        //        {
//        //            //---------------Set up test pack-------------------
//        //            List<IModelClass> modelClasses = new List<IModelClass>();
//        //            BoTestProjectGenerator boTestProjectGenerator = new BoTestProjectGenerator();
//        //            //---------------Assert Precondition----------------
//        //            Assert.IsNull(boTestProjectGenerator.ModelElements);
//        //            //---------------Execute Test ----------------------
//        //            boTestProjectGenerator.ModelElements = modelClasses;
//        //            //---------------Test Result -----------------------
//        //            Assert.AreEqual(modelClasses, boTestProjectGenerator.ModelElements);
//        //        }
//        //
//        //        [Test]
//        //        public void TestGenerate_Fails_ModelClassesNotSet()
//        //        {
//        //            //---------------Set up test pack-------------------
//        //            BoTestProjectGenerator boTestProjectGenerator = CreateBoTestProjectReadyToGenerate();
//        //            boTestProjectGenerator.ModelElements = null;
//        //            //---------------Assert Precondition----------------
//        //            Assert.IsNull(boTestProjectGenerator.ModelElements);
//        //            //---------------Execute Test ----------------------
//        //            Exception exception = null;
//        //            try
//        //            {
//        //                boTestProjectGenerator.Generate();
//        //            }
//        //            catch (Exception ex)
//        //            {
//        //                exception = ex;
//        //            }
//        //            //---------------Test Result -----------------------
//        //            Assert.IsNotNull(exception, "Exception Expected");
//        //            Assert.IsInstanceOf(typeof(PropertyMissingException), exception);
//        //            PropertyMissingException propertyMissingException = (PropertyMissingException)exception;
//        //            Assert.AreEqual("ModelElements", propertyMissingException.PropertyName);
//        //        }
//        //
//        //        [Test]
//        //        public void TestGenerate_Creates_ProjectFile_IfDoesNotExist()
//        //        {
//        //            //---------------Set up test pack-------------------
//        //            BoTestProjectGenerator boTestProjectGenerator = CreateBoTestProjectReadyToGenerate();
//        //            ProjectFileManager boProjectFileManager = CreateRandomProjectFile(boTestProjectGenerator.BoProjectFileName);
//        //            //---------------Assert Precondition----------------
//        //            Assert.IsFalse(File.Exists(boTestProjectGenerator.ProjectFileName));
//        //            //---------------Execute Test ----------------------
//        //            boTestProjectGenerator.Generate();
//        //            //---------------Test Result -----------------------
//        //            AssertProjectGeneratedCorrectly(boTestProjectGenerator, boProjectFileManager);
//        //        }
//        //
//        //        public abstract class TestBoTestProjectGenerator_GeneratedFile : TestProjectGeneratorBase_GeneratedFile
//        //        {
//        //            protected override IProjectGenerator CreateProjectReadyToGenerate()
//        //            {
//        //                return CreateBoTestProjectReadyToGenerate();
//        //            }
//        //        }
//        //
//        //        public class TestBoTestProjectGenerator_GeneratedFile_TestBaseClass : TestBoTestProjectGenerator_GeneratedFile
//        //        {
//        //            private const string _className = "TestBase";
//        //
//        //            protected override IProjectGenerator CreateProjectReadyToGenerate()
//        //            {
//        //                return CreateBoTestProjectReadyToGenerate();
//        //            }
//        //
//        //            protected override void AssertFileGeneratedCorrectly(IProjectGenerator projectGenerator, string fileContents)
//        //            {
//        //                StringAssert.Contains("using Habanero.BO;", fileContents);
//        //                StringAssert.Contains(string.Format("namespace {0}", projectGenerator.ProjectName), fileContents);
//        //                StringAssert.Contains(string.Format("public class {0}", _className), fileContents);
//        //                //TDO check connection string set correctly
//        //            }
//        //
//        //            protected override string GetFileName()
//        //            {
//        //                return _className + ".cs";
//        //            }
//        //        }
//        //
//        //        public class TestBoTestProjectGenerator_GeneratedFile_TestUtils : TestBoTestProjectGenerator_GeneratedFile
//        //        {
//        //            private const string _className = "TestUtils";
//        //
//        //            //TDO: Test what happens if there are no BO's
//        //
//        //            protected override IProjectGenerator CreateProjectReadyToGenerate()
//        //            {
//        //                BoTestProjectGenerator projectGenerator = CreateBoTestProjectReadyToGenerate();
//        //                DMClass dmClass = new DMClass();
//        //                dmClass.ClassName = _className;
//        //                dmClass.AssemblyName = projectGenerator.ProjectName;
//        //                projectGenerator.ModelElements.Add(dmClass);
//        //                return projectGenerator;
//        //            }
//        //
//        //            protected override void AssertFileGeneratedCorrectly(IProjectGenerator projectGenerator, string fileContents)
//        //            {
//        //                BoTestProjectGenerator boTestProjectGenerator = (BoTestProjectGenerator)projectGenerator;
//        //                IModelClass dmClass = boTestProjectGenerator.ModelElements[0];
//        //                StringAssert.Contains("using Habanero.BO;", fileContents);
//        //                StringAssert.Contains(string.Format("namespace {0}", dmClass.AssemblyName), fileContents);
//        //                StringAssert.Contains(string.Format("public class {0}", _className), fileContents);
//        //            }
//        //
//        //            protected override string GetFileName()
//        //            {
//        //                return _className + ".cs";
//        //            }
//        //        }
//        //
//        //        //[TestFixture]
//        //        //public class TestBoTestProjectGenerator_GeneratedFile_SampleClass_Def
//        //        //{
//        //        //    private string _className;
//        //
//        //        //    protected string GetFileName()
//        //        //    {
//        //        //        return _className + ".Def.cs";
//        //        //    }
//        //
//        //        //    public TestBoTestProjectGenerator_GeneratedFile_SampleClass_Def()
//        //        //    {
//        //        //        _className = GetRandomString();
//        //        //    }
//        //
//        //        //    protected BoTestProjectGenerator CreateProjectReadyToGenerate()
//        //        //    {
//        //        //        BoTestProjectGenerator projectGenerator = CreateBoProjectReadyToGenerate();
//        //        //        DMClass dmClass = new DMClass();
//        //        //        dmClass.ClassName = _className;
//        //        //        projectGenerator.ModelElements.Add(dmClass);
//        //        //        return projectGenerator;
//        //        //    }
//        //
//        //        //    [Test]
//        //        //    public void TestGenerate_GeneratesFile_IfDoesNotExist()
//        //        //    {
//        //        //        //---------------Set up test pack-------------------
//        //        //        IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
//        //        //        string fileName = Path.Combine(projectGenerator.ProjectPath, GetFileName());
//        //        //        //---------------Assert Precondition----------------
//        //        //        Assert.IsFalse(File.Exists(fileName));
//        //        //        //---------------Execute Test ----------------------
//        //        //        projectGenerator.Generate();
//        //        //        //---------------Test Result -----------------------
//        //        //        Assert.IsTrue(Directory.Exists(projectGenerator.ProjectPath), "Folder should exist.");
//        //        //        Assert.IsTrue(File.Exists(fileName), "File should have been generated because it didn't exist.");
//        //        //    }
//        //
//        //        //    [Test]
//        //        //    public void TestGenerate_DoesRegenerate_IfExists()
//        //        //    {
//        //        //        //---------------Set up test pack-------------------
//        //        //        IProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
//        //        //        projectGenerator.Generate();
//        //        //        string fileName = Path.Combine(projectGenerator.ProjectPath, GetFileName());
//        //        //        string tempFileContents = GetRandomString();
//        //        //        File.WriteAllText(fileName, tempFileContents);
//        //        //        //---------------Assert Precondition----------------
//        //        //        Assert.AreEqual(tempFileContents, File.ReadAllText(fileName));
//        //        //        //---------------Execute Test ----------------------
//        //        //        projectGenerator.Generate();
//        //        //        //---------------Test Result -----------------------
//        //        //        Assert.AreNotEqual(tempFileContents, File.ReadAllText(fileName));
//        //        //    }
//        //
//        //        //    [Test]
//        //        //    public void TestFileAddedToProject()
//        //        //    {
//        //        //        //---------------Set up test pack-------------------
//        //        //        BoTestProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
//        //        //        //---------------Assert Precondition----------------
//        //        //        //---------------Execute Test ----------------------
//        //        //        projectGenerator.Generate();
//        //        //        //---------------Test Result -----------------------
//        //        //        ProjectFileManager projectFileManager = new ProjectFileManager(projectGenerator.ProjectFileName, OutputType.Library);
//        //        //        string fileName = Path.Combine(projectGenerator.ProjectPath, GetFileName());
//        //        //        string stubFileName = Path.Combine(projectGenerator.ProjectPath, _className + ".cs");
//        //        //        Assert.IsTrue(projectFileManager.HasCodeFile(fileName, stubFileName), "File Should be added to the project.");
//        //        //    }
//        //
//        //        //    [Test]
//        //        //    public void TestInheritsFromSuperClass()
//        //        //    {
//        //        //        //---------------Set up test pack-------------------
//        //        //        BoTestProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
//        //        //        DMClass dmClass = (DMClass)projectGenerator.ModelElements[0];
//        //        //        dmClass.SuperClassName = GetRandomString();
//        //        //        dmClass.SuperClassAssemblyName = GetRandomString();
//        //        //        //---------------Assert Precondition----------------
//        //        //        //---------------Execute Test ----------------------
//        //        //        projectGenerator.Generate();
//        //        //        //---------------Test Result -----------------------
//        //        //        string contents = File.ReadAllText(Path.Combine(projectGenerator.ProjectPath, dmClass.ClassName + ".Def.cs"));
//        //        //        StringAssert.Contains(string.Format("public partial class {0} : {1}", dmClass.ClassName, dmClass.SuperClassName), contents);
//        //        //        StringAssert.Contains(string.Format("using {0};", dmClass.SuperClassAssemblyName), contents);
//        //        //    }
//        //
//        //        //    [Test]
//        //        //    public void TestInheritsFromSuperClass_FromOwnNamespace()
//        //        //    {
//        //        //        //---------------Set up test pack-------------------
//        //        //        BoTestProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
//        //        //        DMClass dmClass = (DMClass)projectGenerator.ModelElements[0];
//        //        //        dmClass.AssemblyName = GetRandomString();
//        //        //        dmClass.SuperClassName = GetRandomString();
//        //        //        dmClass.SuperClassAssemblyName = dmClass.AssemblyName;
//        //        //        //---------------Assert Precondition----------------
//        //        //        //---------------Execute Test ----------------------
//        //        //        projectGenerator.Generate();
//        //        //        //---------------Test Result -----------------------
//        //        //        string contents = File.ReadAllText(Path.Combine(projectGenerator.ProjectPath, dmClass.ClassName + ".Def.cs"));
//        //        //        StringAssert.Contains(string.Format("public partial class {0} : {1}", dmClass.ClassName, dmClass.SuperClassName), contents);
//        //        //        Assert.AreEqual(-1, contents.IndexOf(string.Format("using {0};", dmClass.SuperClassAssemblyName), StringComparison.InvariantCultureIgnoreCase), "Class file should not contain a using for it's own namespace.");
//        //        //    }
//        //
//        //        //    [Test]
//        //        //    public void TestInheritsFromNothing()
//        //        //    {
//        //        //        //---------------Set up test pack-------------------
//        //        //        BoTestProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
//        //        //        DMClass dmClass = (DMClass)projectGenerator.ModelElements[0];
//        //        //        //---------------Assert Precondition----------------
//        //        //        //---------------Execute Test ----------------------
//        //        //        projectGenerator.Generate();
//        //        //        //---------------Test Result -----------------------
//        //        //        string contents = File.ReadAllText(Path.Combine(projectGenerator.ProjectPath, dmClass.ClassName + ".Def.cs"));
//        //        //        StringAssert.Contains(string.Format("public partial class {0} : BusinessObject", dmClass.ClassName), contents);
//        //        //    }
//        //
//        //        //    [Test]
//        //        //    public void TestPropertyCreated_NonValueType()
//        //        //    {
//        //        //        //---------------Set up test pack-------------------
//        //        //        BoTestProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
//        //        //        IModelClass dmClass = projectGenerator.ModelElements[0];
//        //        //        IModelProperty property = new DMProperty();
//        //        //        property.PropertyName = GetRandomString();
//        //        //        IModelPropertyType propertyType = (IModelPropertyType)property.PropertyType;
//        //        //        propertyType.PropertyTypeName = GetRandomString();
//        //        //        propertyType.AssemblyName = GetRandomString();
//        //        //        propertyType.IsValueType = false;
//        //        //        dmClass.Properties.Add(property);
//        //        //        //---------------Assert Precondition----------------
//        //        //        Assert.AreEqual(1, dmClass.Properties.Count);
//        //        //        //---------------Execute Test ----------------------
//        //        //        projectGenerator.Generate();
//        //        //        //---------------Test Result -----------------------
//        //        //        IModelProperty modelProperty = dmClass.Properties[0];
//        //        //        string contents = File.ReadAllText(Path.Combine(projectGenerator.ProjectPath, dmClass.ClassName + ".Def.cs"));
//        //        //        StringAssert.Contains(string.Format("public virtual {0} {1}", propertyType.PropertyTypeName, modelProperty.PropertyName), contents);
//        //        //        StringAssert.Contains(string.Format("using {0};", propertyType.AssemblyName), contents);
//        //        //    }
//        //
//        //        //    [Test]
//        //        //    public void TestPropertyCreated_ValueType()
//        //        //    {
//        //        //        //---------------Set up test pack-------------------
//        //        //        BoTestProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
//        //        //        IModelClass dmClass = projectGenerator.ModelElements[0];
//        //        //        IModelProperty property = new DMProperty();
//        //        //        property.PropertyName = GetRandomString();
//        //        //        IModelPropertyType propertyType = (IModelPropertyType)property.PropertyType;
//        //        //        propertyType.PropertyTypeName = GetRandomString();
//        //        //        propertyType.AssemblyName = GetRandomString();
//        //        //        propertyType.IsValueType = true;
//        //        //        dmClass.Properties.Add(property);
//        //        //        //---------------Assert Precondition----------------
//        //        //        Assert.AreEqual(1, dmClass.Properties.Count);
//        //        //        //---------------Execute Test ----------------------
//        //        //        projectGenerator.Generate();
//        //        //        //---------------Test Result -----------------------
//        //        //        IModelProperty modelProperty = dmClass.Properties[0];
//        //        //        string contents = File.ReadAllText(Path.Combine(projectGenerator.ProjectPath, dmClass.ClassName + ".Def.cs"));
//        //        //        StringAssert.Contains(string.Format("public virtual {0}? {1}", propertyType.PropertyTypeName, modelProperty.PropertyName), contents);
//        //        //        StringAssert.Contains(string.Format("using {0};", propertyType.AssemblyName), contents);
//        //        //    }
//        //
//        //        //    [Test]
//        //        //    public void TestRelationshipCreated_Multiple()
//        //        //    {
//        //        //        //---------------Set up test pack-------------------
//        //        //        BoTestProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
//        //        //        IModelClass dmClass = projectGenerator.ModelElements[0];
//        //        //        DMRelationship relationship = new DMRelationship();
//        //        //        relationship.RelatedClass = GetRandomString();
//        //        //        relationship.RelatedAssembly = GetRandomString();
//        //        //        relationship.IsMultiple = true;
//        //        //        relationship.RelationshipName = GetRandomString();
//        //        //        dmClass.Relationships.Add(relationship);
//        //        //        //---------------Assert Precondition----------------
//        //        //        Assert.AreEqual(1, dmClass.Relationships.Count);
//        //        //        //---------------Execute Test ----------------------
//        //        //        projectGenerator.Generate();
//        //        //        //---------------Test Result -----------------------
//        //        //        IModelRelationship modelRelationship = dmClass.Relationships[0];
//        //        //        string contents = File.ReadAllText(Path.Combine(projectGenerator.ProjectPath, dmClass.ClassName + ".Def.cs"));
//        //        //        StringAssert.Contains(string.Format("public virtual BusinessObjectCollection<{0}> {1}", modelRelationship.RelatedClass, modelRelationship.RelationshipName), contents);
//        //        //        StringAssert.Contains(string.Format("using {0};", relationship.RelatedAssembly), contents);
//        //        //    }
//        //
//        //        //    [Test]
//        //        //    public void TestRelationshipCreated_Single()
//        //        //    {
//        //        //        //---------------Set up test pack-------------------
//        //        //        BoTestProjectGenerator projectGenerator = CreateProjectReadyToGenerate();
//        //        //        IModelClass dmClass = projectGenerator.ModelElements[0];
//        //        //        DMRelationship relationship = new DMRelationship();
//        //        //        relationship.RelatedClass = GetRandomString();
//        //        //        relationship.RelatedAssembly = GetRandomString();
//        //        //        relationship.IsMultiple = false;
//        //        //        relationship.RelationshipName = GetRandomString();
//        //        //        dmClass.Relationships.Add(relationship);
//        //        //        //---------------Assert Precondition----------------
//        //        //        Assert.AreEqual(1, dmClass.Relationships.Count);
//        //        //        //---------------Execute Test ----------------------
//        //        //        projectGenerator.Generate();
//        //        //        //---------------Test Result -----------------------
//        //        //        IModelRelationship modelRelationship = dmClass.Relationships[0];
//        //        //        string contents = File.ReadAllText(Path.Combine(projectGenerator.ProjectPath, dmClass.ClassName + ".Def.cs"));
//        //        //        StringAssert.Contains(string.Format("public virtual {0} {1}", modelRelationship.RelatedClass, modelRelationship.RelationshipName), contents);
//        //        //        StringAssert.Contains(string.Format("using {0};", relationship.RelatedAssembly), contents);
//        //        //    }
//        //        //}
//        protected override IProjectGenerator CreateProjectGenerator()
//        {
//            //return new BoTestProjectGenerator("d", "d", "d", "d", new List<IModelClass>());
//            throw new System.NotImplementedException();
//        }

//        protected override IProjectGenerator CreateProjectReadyToGenerate()
//        {
//            throw new System.NotImplementedException();
//        }
//    }


//}
